﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="isik_jada_item", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(IsikJadaItem))]
    public class IsikJadaItemSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IIsikJadaItem clazz;
        
        public IsikJadaItemSerializer(IIsikJadaItem clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("isikukood");
            if (clazz.Isikukood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikukood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikukood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("perekonnanimi");
            if (clazz.Perekonnanimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Perekonnanimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Perekonnanimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("synnikpv");
            if (clazz.Synnikpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Synnikpv))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Synnikpv");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("toimik_jada");
            if (clazz.ToimikJada!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("toimik_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis", clazz.ToimikJada.Count);
                for (int x = 0; ((clazz.ToimikJada != null) 
                            && (x < clazz.ToimikJada.Count)); x = (x + 1)) {
                    if (clazz.ToimikJada[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaToimikJada = this.GetMetaData(clazz.ToimikJada[x]);
                        Writer.WriteTypeAttribute(metaToimikJada.TypeQualifiedName.Namespace, metaToimikJada.TypeQualifiedName.Name);
                        metaToimikJada.NewSerializer(clazz.ToimikJada[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ToimikJada");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "isikukood")) {
                goto isikukood;
            }
            else {
                if ((Reader.LocalName == "eesnimi")) {
                    goto eesnimi;
                }
                else {
                    if ((Reader.LocalName == "perekonnanimi")) {
                        goto perekonnanimi;
                    }
                    else {
                        if ((Reader.LocalName == "synnikpv")) {
                            goto synnikpv;
                        }
                        else {
                            if ((Reader.LocalName == "toimik_jada")) {
                                goto toimik_jada;
                            }
                            else {
                                return;
                            }
                        }
                    }
                }
            }
        isikukood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isik_jada_item>isikukood");
            }
            clazz.Isikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isikukood")).Value;
            goto START;
        eesnimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isik_jada_item>eesnimi");
            }
            clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
            goto START;
        perekonnanimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isik_jada_item>perekonnanimi");
            }
            clazz.Perekonnanimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("perekonnanimi")).Value;
            goto START;
        synnikpv:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isik_jada_item>synnikpv");
            }
            clazz.Synnikpv = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("synnikpv")).Value;
            goto START;
        toimik_jada:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isik_jada_item>toimik_jada");
            }
            clazz.ToimikJada = new System.Collections.Generic.List<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimikJadaItem>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("toimik_jada");
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>isik_jada_item>toimik_jada>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaToimikJada = this.GetMetaData<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimikJadaItem>(Reader, "toimik_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis");
                    global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimikJadaItem item = metaToimikJada.NewEntity<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimikJadaItem>();
                    clazz.ToimikJada.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("item");
                        metaToimikJada.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
